<%@ page language="java" import="com.google.gson.Gson" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@	page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="up7.biz.PathGuidBuilder" %>
<%@ page import="up7.biz.up7_biz_event" %>
<%@	page import="up7.model.FileInf" %>
<%@	page import="up7.utils.PathTool" %>
<%@ page import="up7.utils.WebBase" %>
<%
    out.clear();
	/*
		所有单个文件均以md5模式存储。
		更新记录：
			2023-02-28 远程路径转为相对路径
		JSON格式化工具：http://tool.oschina.net/codeformat/json
	*/
    WebBase wb = new WebBase(pageContext);
    String uid 			= wb.reqStr("uid");
    String id			= request.getParameter("id");
    long lenLoc 		= wb.reqLong("lenLoc");//数字化的文件大小。12021
    String sizeLoc 		= request.getParameter("sizeLoc");//格式化的文件大小。10MB
    int blockSize	= wb.reqInt("blockSize");
    int blockCount	= wb.reqInt("blockCount");
    String callback     = request.getParameter("callback");
    String pathLoc		= request.getParameter("pathLoc");
    pathLoc 			= PathTool.url_decode(pathLoc);

    //参数为空
    if (StringUtils.isBlank(sizeLoc))
    {
        out.write(callback + "({\"value\":null})");
        return;
    }

    FileInf fileSvr      = new FileInf();
    fileSvr.id           = id;
    fileSvr.uid          = uid;
    fileSvr.nameLoc      = PathTool.getName(pathLoc);
    fileSvr.pathLoc      = pathLoc;
    fileSvr.lenLoc       = lenLoc;
    fileSvr.sizeLoc      = sizeLoc;
    fileSvr.blockSize    = blockSize;
    fileSvr.blockCount	 = blockCount;
    fileSvr.nameSvr      = fileSvr.nameLoc;

    //所有单个文件均以guid方式存储
    PathGuidBuilder pb   = new PathGuidBuilder();
    fileSvr.pathSvr      = pb.genFile(fileSvr);

    //触发事件
    up7_biz_event.file_create(fileSvr);

    //将路径转换成相对路径
    fileSvr.pathSvr = pb.absToRel(fileSvr.pathSvr);

    Gson gson = new Gson();
    String json = gson.toJson(fileSvr);
    json = PathTool.url_encode(json);
    json = callback + "({\"value\":\"" + json + "\"})";//返回jsonp格式数据。
    out.write(json);
%>